home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Kant Generator Pro 1.2 / src / Shell ƒ / about.c next >
C/C++ Source or Header  |  1995-02-14  |  9KB  |  315 lines

  1. #include "about.h"
  2. #include "environment.h"
  3. #include "graphics.h"
  4. #include "pict utilities.h"
  5. #include "offscreen layer.h"
  6. #include "prefs.h"
  7. #include "util.h"
  8. #include "text twiddling.h"
  9. #include "file utilities.h"
  10. #include "window layer.h"
  11. #include "program globals.h"
  12.  
  13. #define DEAD_SPACE_H        10
  14. #define DEAD_SPACE_V        10
  15. #define kLogoWidth            73
  16. #define kLogoHeight            40
  17. #define kTextHeight            15
  18. #define kLogoPictID            128
  19. #define kAboutTextID        128
  20. #define kCalligraphyFont    36
  21. #define kScrollSpeed        1
  22.  
  23. static    Boolean            gSetupDone=FALSE;
  24. static    MyOffscreenComboPtr    gLogoComboPtr=0L;
  25. static    MyOffscreenComboPtr    gTextComboPtr=0L;
  26. static    Handle            gTheTextHandle=0L;
  27. static    Boolean            gScrollingAvailable=FALSE;
  28. static    Str31            gVersionStr;
  29. static    Boolean            gDoFade=TRUE;
  30. static    Boolean            gDoChangeDepth=FALSE;
  31.  
  32. static    void DrawTheLogos(WindowPtr theWindow, Boolean doFade, short theDepth);
  33. static void DrawTheTextPattern(WindowPtr theWindow, MyOffscreenComboPtr offscreenComboPtr,
  34.                 short theDepth);
  35.  
  36. void SetupTheAboutWindow(WindowPtr theWindow)
  37. {
  38.     unsigned char    *titleStr="\pAbout";
  39.     Point            topLeft;
  40.     unsigned char    *versionBit="\pversion ";
  41.     Str255            versionNumberString;
  42.     
  43.     SetWindowWidth(theWindow, 400);
  44.     SetWindowHeight(theWindow, DEAD_SPACE_V*3+kTextHeight+kLogoHeight);
  45.     SetWindowType(theWindow, movableDBoxProc);
  46.     SetWindowTitle(theWindow, titleStr);
  47.     SetWindowHasCloseBox(theWindow, TRUE);
  48.     SetWindowMaxDepth(theWindow, 8);
  49.     SetWindowDepth(theWindow, 8);
  50.     SetWindowIsFloat(theWindow, FALSE);
  51.     SetWindowAutoCenter(theWindow, FALSE);
  52.     topLeft.v=(qd.screenBits.bounds.bottom-qd.screenBits.bounds.top-GetWindowHeight(theWindow))/3+
  53.         qd.screenBits.bounds.top;
  54.     topLeft.h=(qd.screenBits.bounds.right-qd.screenBits.bounds.left-GetWindowWidth(theWindow))/2+
  55.         qd.screenBits.bounds.left;
  56.     SetWindowTopLeft(theWindow, topLeft);
  57.     if (gSetupDone)
  58.         return;
  59.     
  60.     gSetupDone=TRUE;
  61.     gNeedToOpenWindow=FALSE;
  62.     GetVersionString(versionNumberString);
  63.     Mymemcpy((Ptr)gVersionStr, (Ptr)versionBit, versionBit[0]+1);
  64.     AppendStr255(gVersionStr, versionNumberString);
  65. }
  66.  
  67. void OpenTheAboutWindow(WindowPtr theWindow)
  68. /* leaks memory on error */
  69. {
  70.     Rect             logoSourceRect, logoDestRect;
  71.     Rect            titleSourceRect, titleDestRect;
  72.     PicHandle        logoPict;
  73.     unsigned char    *titleStr=APPLICATION_NAME;
  74.     short            realDepth, maxDepth, theDepth;
  75.     
  76.     realDepth=GetWindowRealDepth(theWindow);
  77.     maxDepth=GetWindowMaxDepth(theWindow);
  78.     theDepth=(realDepth>=maxDepth) ? maxDepth : realDepth;
  79.     
  80.     if (gLogoComboPtr==0L)
  81.     {
  82.         logoPict=0L;
  83.         SetRect(&logoSourceRect, 0, 0, kLogoWidth, kLogoHeight);
  84.         logoDestRect=logoSourceRect;
  85.         OffsetRect(&logoDestRect, DEAD_SPACE_H, DEAD_SPACE_V);
  86.         gLogoComboPtr=AllocateOffscreenCombo(theWindow, &logoSourceRect, &logoDestRect, 0, 0L, 0, 0);
  87.         if (gLogoComboPtr==0L)
  88.             return;
  89.         SetPortToOffscreenWindow(&(gLogoComboPtr->offscreenWorldRec));
  90.         logoPict=DrawThePicture(logoPict, kLogoPictID, 0, 0);
  91.         InvertRect(&logoSourceRect);
  92.         SetPortToOnscreenWindow(theWindow, &(gLogoComboPtr->offscreenWorldRec));
  93.         logoPict=ReleaseThePict(logoPict);
  94.         
  95.         SetRect(&titleSourceRect, 0, 0, GetWindowWidth(theWindow), kTextHeight);
  96.         titleDestRect=titleSourceRect;
  97.         OffsetRect(&titleDestRect, 0, GetWindowHeight(theWindow)-kTextHeight-DEAD_SPACE_V);
  98.         gTheTextHandle=GetResource('TEXT', kAboutTextID);
  99.         AppendStr255ToHandle(gTheTextHandle, gMyName);
  100.         if (gMyOrg[0]!=0x00)
  101.         {
  102.             AppendStr255ToHandle(gTheTextHandle, "\p, ");
  103.             AppendStr255ToHandle(gTheTextHandle, gMyOrg);
  104.         }
  105.         AppendStr255ToHandle(gTheTextHandle, "\p.     -=-     ");
  106.         gTextComboPtr=AllocateOffscreenCombo(theWindow, &titleSourceRect, &titleDestRect, kScrollSpeed,
  107.             gTheTextHandle, geneva, 9);
  108.         if (gTextComboPtr==0L)
  109.             return;
  110.         SetPortToOffscreenWindow(&(gTextComboPtr->offscreenWorldRec));
  111.         FillRect(&(gTextComboPtr->offscreenWorldRec.offscreenPtr->portRect), &qd.black);
  112.         SetPortToOnscreenWindow(theWindow, &(gTextComboPtr->offscreenWorldRec));
  113.         DrawTheTextPattern(theWindow, gTextComboPtr, theDepth);
  114.         gScrollingAvailable=TRUE;
  115.     }
  116.     
  117.     FillRect(&(theWindow->portRect), &qd.black);
  118.     if ((theDepth>=8) && (gDoFade))
  119.     {
  120.         DrawTheLogos(theWindow, TRUE, theDepth);
  121.     }
  122. }
  123.  
  124. void IdleInTheAboutWindow(WindowPtr theWindow)
  125. {
  126.     if (gDoChangeDepth)
  127.     {
  128.         DisposeTheAboutWindow(theWindow);
  129.         gDoFade=FALSE;
  130.         OpenTheAboutWindow(theWindow);
  131.         gDoFade=TRUE;
  132.         InvalRect(&(theWindow->portRect));
  133.         gDoChangeDepth=FALSE;
  134.     }
  135.     else
  136.     {
  137.         if ((gScrollingAvailable) && (!gIsInBackground))
  138.             ScrollTextCombo(gTextComboPtr);
  139.     }
  140. }
  141.  
  142. void DisposeTheAboutWindow(WindowPtr theWindow)
  143. {
  144.     gLogoComboPtr=DisposeOffscreenCombo(gLogoComboPtr);
  145.     gTextComboPtr=DisposeOffscreenCombo(gTextComboPtr);
  146.     ReleaseResource(gTheTextHandle);
  147.     gTheTextHandle=0L;
  148. }
  149.  
  150. void ShutDownTheAboutWindow(void)
  151. {
  152. }
  153.  
  154. void KeyDownInAboutWindow(WindowPtr theWindow, unsigned char theChar)
  155. {
  156.     CloseTheWindow(theWindow);
  157. }
  158.  
  159. void MouseDownInAboutWindow(WindowPtr theWindow, Point thePoint)
  160. {
  161.     CloseTheWindow(theWindow);
  162. }
  163.  
  164. void ChangeDepthTheAboutWindow(WindowPtr theWindow)
  165. {
  166.     gDoChangeDepth=TRUE;
  167. }
  168.  
  169. void DrawTheAboutWindow(WindowPtr theWindow, short theDepth)
  170. {
  171.     short            titleWidth, versionWidth;
  172.     unsigned char    *titleStr=APPLICATION_NAME;
  173.     
  174.     FillRect(&(theWindow->portRect), &qd.black);
  175.     SetTheDrawingFont(kCalligraphyFont, 12, 0);
  176.     TextMode(notSrcCopy);
  177.     titleWidth=StringWidth(titleStr);
  178.     MoveTo((GetWindowWidth(theWindow)-titleWidth)/2, DEAD_SPACE_V+18);
  179.     DrawString(titleStr);
  180.     SetTheDrawingFont(geneva, 9, 0);
  181.     versionWidth=StringWidth(gVersionStr);
  182.     MoveTo((GetWindowWidth(theWindow)-versionWidth)/2, DEAD_SPACE_V*2+15+10);
  183.     DrawString(gVersionStr);
  184.     UseDefaultDrawingFont();
  185.     TextMode(srcCopy);
  186. }
  187.  
  188. void CopybitsTheAboutWindow(WindowPtr theWindow, WindowPtr offscreenWindowPtr)
  189. {
  190.     RgnHandle        logoRgn, copyRgn;
  191.     Rect            logoRect;
  192.     
  193.     copyRgn=NewRgn();
  194.     logoRgn=NewRgn();
  195.     RectRgn(copyRgn, &(theWindow->portRect));
  196.     logoRect=gLogoComboPtr->destRect;
  197.     RectRgn(logoRgn, &logoRect);
  198.     DiffRgn(copyRgn, logoRgn, copyRgn);
  199.     SetEmptyRgn(logoRgn);
  200.     logoRect.right=GetWindowWidth(theWindow)-DEAD_SPACE_H;
  201.     logoRect.left=logoRect.right-kLogoWidth;
  202.     RectRgn(logoRgn, &logoRect);
  203.     DiffRgn(copyRgn, logoRgn, copyRgn);
  204.     
  205.     CopyBits(    &(offscreenWindowPtr->portBits),
  206.                 &(theWindow->portBits),
  207.                 &(theWindow->portRect),
  208.                 &(theWindow->portRect), 0, copyRgn);
  209.     
  210.     DrawTheLogos(theWindow, FALSE, GetWindowDepth(theWindow));
  211.     CopybitsCombo(gTextComboPtr);
  212.     
  213.     DisposeRgn(copyRgn);
  214.     DisposeRgn(logoRgn);
  215. }
  216.  
  217. static    void DrawTheLogos(WindowPtr theWindow, Boolean doFade, short theDepth)
  218. {
  219.     unsigned short    j, numRows, startJ;
  220.     RGBColor        patternColor;
  221.     Rect            logoRect1, logoRect2, sourceRect;
  222.     PixPatHandle    backgroundppat;
  223.     
  224.     logoRect1=logoRect2=gLogoComboPtr->destRect;
  225.     logoRect2.right=GetWindowWidth(theWindow)-DEAD_SPACE_H;
  226.     logoRect2.left=logoRect2.right-kLogoWidth;
  227.     sourceRect=gLogoComboPtr->sourceRect;
  228.     
  229.     if (theDepth>=4)
  230.     {
  231.         numRows=kLogoHeight;
  232.         patternColor.red=patternColor.green=0;
  233.         if (theDepth>=8)
  234.             startJ=doFade ? 0 : 64;
  235.         else
  236.             startJ=64;
  237.             
  238.         for (j=startJ; j<=64; j++)
  239.         {
  240.             if (j<64)
  241.                 patternColor.blue=j*1024;
  242.             else
  243.                 patternColor.blue=65535;
  244.             SetPortToOffscreenWindow(&(gLogoComboPtr->patternWorldRec));
  245.             backgroundppat=NewPixPat();
  246.             MakeRGBPat(backgroundppat, &patternColor);
  247.             FillCRect(&sourceRect, backgroundppat);
  248.             DisposePixPat(backgroundppat);
  249.             SetPortToOnscreenWindow(theWindow, &(gLogoComboPtr->patternWorldRec));
  250.             CopybitsCombo(gLogoComboPtr);
  251.             CopyBits(&(theWindow->portBits), &(theWindow->portBits), &logoRect1, &logoRect2, 0, 0L);
  252.         }
  253.     }
  254.     else
  255.     {
  256.         SetPortToOffscreenWindow(&(gLogoComboPtr->patternWorldRec));
  257.         EraseRect(&sourceRect);
  258.         SetPortToOnscreenWindow(theWindow, &(gLogoComboPtr->patternWorldRec));
  259.         CopybitsCombo(gLogoComboPtr);
  260.         CopyBits(&(theWindow->portBits), &(theWindow->portBits), &logoRect1, &logoRect2, 0, 0L);
  261.     }
  262. }
  263.  
  264. static void DrawTheTextPattern(WindowPtr theWindow, MyOffscreenComboPtr offscreenComboPtr,
  265.     short theDepth)
  266. {
  267.     short            i;
  268.     short            WIDTH;
  269.     RGBColor        *theColor;
  270.     Rect            sourceRect;
  271.     
  272.     WIDTH=offscreenComboPtr->sourceRect.right-offscreenComboPtr->sourceRect.left;
  273.     sourceRect=offscreenComboPtr->sourceRect;
  274.     SetPortToOffscreenWindow(&(offscreenComboPtr->patternWorldRec));
  275.     
  276.     if (theDepth>=8)
  277.     {
  278.         theColor=(RGBColor*)NewPtr(sizeof(RGBColor)*WIDTH);
  279.         for (i=0; i<64; i++)
  280.         {
  281.             theColor[i].red=i*1024;
  282.             theColor[i].green=theColor[i].blue=0;
  283.         }
  284.         for (i=64; i<WIDTH-64; i++)
  285.         {
  286.             theColor[i].red=65535;
  287.             theColor[i].green=theColor[i].blue=0;
  288.         }
  289.         for (i=WIDTH-64; i<WIDTH; i++)
  290.         {
  291.             theColor[i].red=theColor[WIDTH-i-1].red;
  292.             theColor[i].green=theColor[i].blue=0;
  293.         }
  294.         for (i=0; i<WIDTH; i++)
  295.         {
  296.             MoveTo(i, 0);
  297.             RGBForeColor(&theColor[i]);
  298.             Line(0, kTextHeight);
  299.         }
  300.         DisposePtr((Ptr)theColor);
  301.     }
  302.     else if (theDepth==4)
  303.     {
  304.         ForeColor(redColor);
  305.         PaintRect(&sourceRect);
  306.         ForeColor(blackColor);
  307.     }
  308.     else
  309.     {
  310.         EraseRect(&sourceRect);
  311.     }
  312.     
  313.     SetPortToOnscreenWindow(theWindow, &(offscreenComboPtr->patternWorldRec));
  314. }
  315.